/*
 * PostgreSqlDAOFactory.java
 *
 * Created on 19 settembre 2007, 14.53
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package it.cnr.icib.daopattern;

/**
 *
 * @author Nino
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Nino
 */
public class SqlLiteDAOFactory {
    
    /** Creates a new instance of PostgreSqlDAOFactory */
    protected Statement stm;
    private static final String DRIVER="org.sqlite.JDBC";
    private static final String DBURL="jdbc:sqlite";

    private Connection conn;

    
    
    
   public SqlLiteDAOFactory(String database,String user, String password) {
        try {
            conn=createConnection(database,user,password);
            stm=conn.createStatement();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
   
   public Statement getStatement(){
       return stm;
   }
   
   public static Connection createConnection(String database,String user, String password){
       Connection con=null;
       try {
           //Carica la classe del drivere per la connessione
           // Load the driver class
           Class.forName(DRIVER);
       } catch (ClassNotFoundException ex) {
           System.out.println("Class not found for Class.forName: " + ex.getMessage());
       }
       try {
           con=DriverManager.getConnection(DBURL+":"+database,user,password);
       } catch (SQLException ex) {
           System.out.println("database access error: " + ex.getMessage());
       }
       
       return con;
   }   
}
